package net.qiqbframework.eventhandling;


import javax.annotation.Nonnull;


public interface EventStore {
    /**
     * 读取某个聚合对象的所有事件
     *
     * @param aggregateId
     * @return
     */
    DomainEventStream readEvents(@Nonnull String aggregateId);

    default DomainEventStream readEvents(@Nonnull String aggregateIdentifier, long firstSequenceNumber) {
        DomainEventStream wholeStream = readEvents(aggregateIdentifier);
        return DomainEventStream.of(wholeStream.asStream().filter(event -> event.getSequenceNumber() >= firstSequenceNumber),
                        wholeStream::getLastSequenceNumber);
    }

    void storeSnapshot(@Nonnull DomainEventMessage<?> snapshot);

}
